import csv
import json


def extract_metadata_names(csv_file):
    with open(csv_file, 'r', encoding='utf-8') as f:
        reader = csv.DictReader(f)
        for row in reader:
            metadata_str = row['metadata']
            try:
                metadata = json.loads(metadata_str)
                # 提取嵌套的name和screen_name
                name = metadata['core']['user_results']['result']['core']['name']
                screen_name = metadata['core']['user_results']['result']['core']['screen_name']
                print(f"{screen_name}\t{name}")
            except (json.JSONDecodeError, KeyError) as e:
                print(f"Error processing row {reader.line_num}: {str(e)}")


if __name__ == "__main__":
    csv_path = r"C:\Users\Administrator\Downloads\twitter-书签-1748007606740.csv"
    extract_metadata_names(csv_path)
